#include "bms_Slave.h"
#include "rtwtypes.h"
#include "Alarm_Recov_sys_cell.h"

#define bms_Slave_IN_Err_pm            ((uint8_T)1U)
#define bms_Slave_IN_Normal_o          ((uint8_T)2U)

void Alarm_Recov_sys_cell_Init(boolean_T *rty_Alarm_flg)
{
  *rty_Alarm_flg = false;
}

void Alarm_Recov_sys_cell(boolean_T rtu_Err_flg, boolean_T rtu_Recov_flg,
  uint16_T rtu_Alarm_time, uint16_T rtu_Recov_time, boolean_T *rty_Alarm_flg,
  DW_Alarm_Recov_sys_cell_T *localDW)
{
  if (localDW->is_active_c35_bms_Slave == 0U) {
    localDW->is_active_c35_bms_Slave = 1U;
    localDW->is_c35_bms_Slave = bms_Slave_IN_Normal_o;
    localDW->count = 1U;
  } else if (localDW->is_c35_bms_Slave == bms_Slave_IN_Err_pm) {
    if (rtu_Recov_flg) {
      localDW->is_c35_bms_Slave = bms_Slave_IN_Normal_o;
      localDW->count = 1U;
    } else {
      uint32_T tmp;
      tmp = localDW->count + 1U;
      if (localDW->count + 1U > 65535U) {
        tmp = 65535U;
      }

      localDW->count = (uint16_T)tmp;
      if (localDW->count >= rtu_Alarm_time) {
        *rty_Alarm_flg = true;
        localDW->count = rtu_Alarm_time;
      }
    }
  } else if (rtu_Err_flg) {
    localDW->is_c35_bms_Slave = bms_Slave_IN_Err_pm;
    localDW->count = 1U;
  } else {
    uint32_T tmp;
    tmp = localDW->count + 1U;
    if (localDW->count + 1U > 65535U) {
      tmp = 65535U;
    }

    localDW->count = (uint16_T)tmp;
    if (localDW->count >= rtu_Recov_time) {
      *rty_Alarm_flg = false;
      localDW->count = rtu_Recov_time;
    }
  }
}
